package com.lovely3x.loginandresgiter.bean;

import android.os.Parcel;

import com.litesuits.orm.db.annotation.PrimaryKey;
import com.litesuits.orm.db.enums.AssignType;
import com.lovely3x.common.managements.user.IUserPreferences;
import com.litesuits.orm.db.annotation.Column;
import com.litesuits.orm.db.annotation.Table;

/**
 * 用户偏好设置
 * Created by lovely3x on 16-3-18.
 */
@Table("user_preferences")
public class SimpleUserPreferences implements IUserPreferences {
    /**
     * 是否开启语音提示
     */
    @Column("turn_audio")
    private boolean turnAudio = true;

    /**
     * 是否开启震动提示
     */
    @Column("turn_vibrate")
    private boolean turnVibrate = true;

    /**
     * 是否开启推送通知
     */
    @Column("turn_push_notification")
    private boolean turnPushNotification = true;

    /**
     * 静默模式
     */
    @Column("silent_mode")
    private boolean silentMod = false;


    @Column("_id")
    @PrimaryKey(AssignType.AUTO_INCREMENT)
    private int id;

    public SimpleUserPreferences(boolean turnAudio, boolean turnVibrate, boolean turnPushNotification) {
        this.turnAudio = turnAudio;
        this.turnVibrate = turnVibrate;
        this.turnPushNotification = turnPushNotification;
    }

    public SimpleUserPreferences() {
    }

    public boolean isTurnAudio() {
        return turnAudio;
    }

    public void setTurnAudio(boolean turnAudio) {
        this.turnAudio = turnAudio;
    }

    public boolean isTurnVibrate() {
        return turnVibrate;
    }

    public void setTurnVibrate(boolean turnVibrate) {
        this.turnVibrate = turnVibrate;
    }

    public boolean isTurnPushNotification() {
        return turnPushNotification;
    }

    public void setTurnPushNotification(boolean turnPushNotification) {
        this.turnPushNotification = turnPushNotification;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "SimpleUserPreferences{" +
                "turnAudio=" + turnAudio +
                ", turnVibrate=" + turnVibrate +
                ", turnPushNotification=" + turnPushNotification +
                ", id=" + id +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        SimpleUserPreferences that = (SimpleUserPreferences) o;

        if (turnAudio != that.turnAudio) return false;
        if (turnVibrate != that.turnVibrate) return false;
        if (turnPushNotification != that.turnPushNotification) return false;
        return id == that.id;

    }

    @Override
    public int hashCode() {
        int result = (turnAudio ? 1 : 0);
        result = 31 * result + (turnVibrate ? 1 : 0);
        result = 31 * result + (turnPushNotification ? 1 : 0);
        result = 31 * result + id;
        return result;
    }

    public boolean isSilentMod() {
        return silentMod;
    }

    public void setSilentMod(boolean silentMod) {
        this.silentMod = silentMod;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByte(turnAudio ? (byte) 1 : (byte) 0);
        dest.writeByte(turnVibrate ? (byte) 1 : (byte) 0);
        dest.writeByte(turnPushNotification ? (byte) 1 : (byte) 0);
        dest.writeInt(this.id);
    }

    protected SimpleUserPreferences(Parcel in) {
        this.turnAudio = in.readByte() != 0;
        this.turnVibrate = in.readByte() != 0;
        this.turnPushNotification = in.readByte() != 0;
        this.id = in.readInt();
    }

    public static final Creator<SimpleUserPreferences> CREATOR = new Creator<SimpleUserPreferences>() {
        @Override
        public SimpleUserPreferences createFromParcel(Parcel source) {
            return new SimpleUserPreferences(source);
        }

        @Override
        public SimpleUserPreferences[] newArray(int size) {
            return new SimpleUserPreferences[size];
        }
    };
}
